<template>
  <div>
    <table-expand ref="table"
                  :columns="columns"
                  :data="basicData"
                  :loading="loading"
                  :config="config"
                  :pageSizeOpts="pageSizeOpts"
                  :pageNavigation="pageNavigation"
                  :queryFormItem="queryFormItem"
                  :collapseFormItem="collapseFormItem"
                  :additionalAction="additionalAction"
                  @loadPage="loadPage"
                  @handleCreate="handleCreate"
                  @handleDetail="handleDetail"
                  @handleEdit="handleEdit"
                  @handleDelete="handleDelete"
                  @handleDeleteMultiple="handleDeleteMultiple"
                  @handleSearch="handleSearch"
                  @handleReset="handleReset"></table-expand>
    <new-add-modal v-bind="addNewPanel"
                   :modelType="modelType"
                   :columns="addFormColumns"
                   :rules="rules"
                   @submit="handleNewAddSubmit"></new-add-modal>
    <edit-modal v-bind="editPanel"
                :modelType="modelType"
                :columns="formColumns"
                :rules="rules"
                @submit="handleEditSubmit"></edit-modal>
    <read-modal v-bind="readPanel"
                :modelType="modelType"
                :columns="columns"
                :rules="rules"></read-modal>
  </div>
</template>

  <script>
    import tableExpand from '@/pages/components/tableExpand.vue';
    import newAddModal from '@/pages/components/newAddModal.vue';
    import editModal from '@/pages/components/editModal.vue';
    import readModal from '@/pages/components/readModal.vue';
    import logicDictionaryMixin from '@/pages/components/mixins/logicDictionaryMixin'
    import { typeClassName } from '@/pages/config/classNameMap';
    import columnsMixin from './config'
    export default {
        components: { tableExpand, newAddModal, editModal, readModal },
        name: 'energyType',
        mixins: [logicDictionaryMixin, columnsMixin],
        data () {
            return {
                classObject: null, // 单个实例
                energyStatus: [], // 能源状态
                energyStatusClassObject: null, // 状态模型
                className: typeClassName['energyType'].className,
                type: typeClassName['energyType'].type,
                modelType: typeClassName['energyType'].modelType,
                addNewPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2
                },
                editPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2,
                    data: {}
                },
                readPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2,
                    data: {}
                },
                rules: {
                    sf_name: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ],
                    sf_code: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ],
                    status: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ]
                },
                loading: false,
                config: {
                    search: true,
                    addButton: true,
                    batchDeleteButton: true,
                    tableSizeIcon: true,
                    fullscreenIcon: true,
                    refreshIcon: false,
                    columnSettingIcon: true,
                    action: true,
                    additionalAction: false,
                    hidePage: true
                },
                pageSizeOpts: [10, 30, 50, 100],
                pageNavigation: { total: 0, pageSize: 20, pageNumber: 1 },
                basicData: [],
                defaultAddData:null
            };
        },
        computed: {
            additionalAction () {
                return { }
            }
        },
        beforeMount () {
            this.classObject = this.$modelObject.create(this.modelType);
            this.energyStatusClassObject = this.$modelObject.create(typeClassName['paramStatus'].modelType);
            this.setEnergyType('paramStatus', this.energyStatusClassObject, 'energyStatus')
            this.loadPage()
        },
        mounted () { },
        methods: {
            setEnergyType (classMapName, classObject, optionName) {
                let filter = {
                    className: typeClassName[classMapName].className,
                    type: typeClassName[classMapName].type
                }
                this.getOptions(filter, classObject).then(res => {
                    this[optionName] = res
                })
            },
            /**
             * 新增确认时条件
             * 能源类型管理，新增时生成编码流水号
             */
            async addCondition(data){
                let flag = true;
                let no = await this.$api.Common.getNextVal('entype')
                data.values['sf_code'] = no;
                return flag;
            }
        }
    };
  </script>
  <style scoped lang="scss"></style>
